package com.xuecheng.content.api;

import com.xuecheng.content.model.po.CourseTeacher;
import com.xuecheng.content.service.CourseTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author :chenjie
 * @date :Created 2023/2/5 20:09
 */
@RestController
@Api("教师管理")
public class CourseTeacherController {
    @Autowired
    CourseTeacherService courseTeacherService;
    @ApiOperation("师资查询")
    @GetMapping("courseTeacher/list/{id}")
    public List<CourseTeacher> list(@PathVariable Long id){
        return courseTeacherService.list(id);
    }
    @ApiOperation("师资新增和修改")
    @PostMapping("/courseTeacher")
    public void saveTeacher(@RequestBody CourseTeacher courseTeacher){
        CourseTeacher byId = courseTeacherService.getById(courseTeacher.getId());
        if(byId==null){
            courseTeacher.setCreateDate(LocalDateTime.now());
        }else {
            courseTeacher.setCreateDate(byId.getCreateDate());
        }
        //时间无法转化为时间类？？？添加序列化器

        courseTeacherService.saveOrUpdate(courseTeacher);
    }
    @ApiOperation("删除师资信息")
    @DeleteMapping("/courseTeacher/course/{coueseId}/{TeacherId}")
    public void removeById(@PathVariable("coueseId") Long courseId,@PathVariable("TeacherId") Long teacherId ){
        courseTeacherService.removeById(courseId,teacherId);
    }
}
